----------------------------------------------------------------
-- TinyCraft Alpha 0.3                                        --
-- 仿minecraft3D类游戏                                        --
-- Author：bk194232658, dt_st9 From 百度贴吧                  --
-- 2015,TC Studio                                             --
-- All Rights Reserve                                         --
----------------------------------------------------------------
supportedOrientations(LANDSCAPE_ANY)
displayMode(OVERLAY)
displayMode(FULLSCREEN)

function setup()
    TCMode = DebugMode      --设置TC运行方式

    if TCMode == DebugMode then
        DebugInit()       --开启调试模式
    elseif TCMode == ReleaseMode then
        displayMode(FULLSCREEN_NO_BUTTONS)
        ErrorHandlerInit()      --开启错误保护模式
    end
    -- profiler = Profiler()
    noSmooth()        --取消模糊 
    math.newRandomseed()        --初始化随机数
    
    modManager = ModManager()       --Mod管理
    -- local m = ModLoader(_,_,readText("Documents:TCTestMod1"))
    -- if m:loadCode() then
    -- modManager:add(m)
    -- end

    startMenu = StartMenu()
    game = Game()
    background(255, 255, 255, 255)
end

function draw()
    -- profiler:update()
    game:draw()     --游戏主循环
    if GameState == Start then
        startMenu:draw()
    elseif GameState == Loading then
        loadScreen:draw()
    elseif GameState == Pause then
        pauseMenu:draw()
    end
end

function touched(touch)
    if GameState == Gaming then
        game:touched(touch)
    elseif GameState == Start then
        startMenu:touched(touch)
    elseif GameState == Loading then
        loadScreen:touched(touch)
    elseif GameState == Pause then
        pauseMenu:touched(touch)
    end
end

function orientationChanged(newOrientation)
    modManager:orientationChanged(newOrientation)
end